/**** Population Class	*******/
 function Population(){
	this.location = "";
	this.coupleStatus ="";
	this.ID = "";
	this.comparisonPoint = "";
	this.ethnicity = "";
}



Population.prototype.toString = function(){
	alert("Location: "+this.location);
} 




/***** Manager Class ********/

function Manager(){

    this.populationArray = new Array();
    this.UIStack = new Array();
    
    
    
}

Manager.prototype.populations = function(){
	
	return this.populationArray;
	
}

Manager.prototype.push = function(component){
    this.UIStack.push(component);
    
    try {
        component.prependTo("#container");
        component.show("slow");
    } 
    catch (e) {
        // alert("Error at Manager.push: " + e);
    }
}


Manager.prototype.pop = function(component){
    this.UIStack.pop(component);
	
	try{
		component.remove();
	}catch(e){
		// alert("Error at Manager.pop(): "+e);
	}
}

Manager.prototype.addPopulation = function(Population){
   
   try {
   	
		this.populationArray[this.populationArray.length] = Population;
	
   }catch(e){
   	// alert("Error at Manager.addPopulation() :"+e);
   }
}


Manager.prototype.getPopSize = function(){
	
	try {
		return this.populationArray.length;
	}catch(e){
		// alert("Error in getPopSize(): "+e);
	}
}



Manager.prototype.getPopulation = function(i){
    if (i < 0 || i >= this.populationArray.length) {
		// alert("Error in Manager.getPopulation: Bad initial state...i= "+i);
		return null;
	}
	
	
	try {
		
		//DEBUG
		// alert("Manager.getPopulation(): At index: "+i+" | the object is: "+this.populationArray[i]);
		// alert("Manager.getPopulation(): Size of the current array is: "+this.populationArray.length);
		
		
		return this.populationArray[i];
	}catch(e){
		// alert("Error in getPopulation, i="+i);
	}
	
}

Manager.prototype.numPopulation = function(){
    return populationArray.length;
}

Manager.prototype.createPopulation = function(){
	
	
	try{
		 newPop = new Population();
		 newPop.ID = this.populationArray.length;
		 newPop.location = "New York";
		 
		 // alert("Manager.createPopulation: "+newPop.toString());
		 
		 this.addPopulation(newPop);
	
	}catch(e){
		// alert("Error at createPopulation: "+e);
	}	
	
	return newPop;
}



function onSuccess(data){

    //$('#test').html(data);
    
    // alert(data);
    // alert('Load was performed.');
    
}

Manager.prototype.fetch = function(url){


    //var url = 'testSite.txt';
    
    try {
    
        //$("#test").load(url);
        var request = $.ajax({
            url: url,
            async: false
        });
        
        
        // alert("Manager.fetch(): "+request.responseText);
        
        var response = request.responseText;
        
        //this.data = new Array();
        
        $(response).find('Population').each(function(){
        
        
            var $thisGuy = $(this);
            
            if ($thisGuy.find('Error').text() == "") {
                mydata.push($thisGuy.find('Value').text());
            }
            
            
            
        });
       
        
        
        
    } 
    catch (e) {
        // alert(e);
    }
    
    
}

